#!/bin/bash

echo "🔍 开始简单监控端口3000..."
echo "按 Ctrl+C 停止监控"
echo "=================================="

while true; do
    timestamp=$(date '+%H:%M:%S')
    
    # 检查端口监听
    if netstat -ano | grep -q ":3000.*LISTENING"; then
        port_status="✅ 监听中"
    else
        port_status="❌ 未监听"
    fi
    
    # 检查HTTP响应
    http_code=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000 2>/dev/null)
    if [ "$http_code" = "200" ]; then
        http_status="✅ 正常"
    else
        http_status="❌ 异常($http_code)"
    fi
    
    # 检查DeepSeek API
    api_response=$(curl -s -X POST "http://localhost:3000/api/deepseek/chat/completions" \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer sk-5005d6e1b94b449998aa8b896876e73e" \
        -d '{"model":"deepseek-chat","messages":[{"role":"user","content":"test"}],"stream":false}' \
        --connect-timeout 3 --max-time 5 2>/dev/null)
    
    if echo "$api_response" | grep -q "choices"; then
        api_status="✅ 正常"
    else
        api_status="❌ 异常"
    fi
    
    echo "[$timestamp] 端口: $port_status | HTTP: $http_status | API: $api_status"
    
    sleep 10
done

